/**
 * @param {number[]} arr
 * @return {number}
 */
var sumOddLengthSubarrays = function (arr) {
  let left = 0
  let res = 0
  while (left < arr.length) {
    let dp = [],
      k = 1
    dp[0] = 0
    for (let right = left; right < arr.length; right++) {
      dp[k] = dp[k - 1] + arr[right]
      if ((right - left + 1) % 2) {
        res += dp[k]
      }
      k++
    }
    left++
  }
  return res
}

sumOddLengthSubarrays([1, 4, 2, 5, 3])
